#include "Blocks/WireThroughBlock.h"
#include "Components/ComponentMiner.h"
#include "Components/ComponentCreature.h"
#include "Components/ComponentCreatureModel.h"
#include <cfloat>

using namespace PocketSurvival::Engine;

namespace PocketSurvival
{
	WireThroughBlock::WireThroughBlock()
	{
		addInheritance(this);
	}

    BlockPlacementData WireThroughBlock::getPlacementValue(ComponentMiner *componentMiner, int32_t value, const TerrainRaycastResult &raycastResult)
    {
		Vector3 forward = componentMiner->componentCreature->componentCreatureModel->getEyeRotation().toMatrix().getForward();
		// 负无穷大
		float num = -FLT_MAX;
		int32_t wiredFace = 0;
		for (int32_t i = 0; i < 6; i++)
		{
			float num2 = Vector3::Dot(CellFace::FaceToVector3(i), forward);
			if (num2 > num)
			{
				num = num2;
				wiredFace = i;
			}
		}
		BlockPlacementData result;
		result.value = Terrain::MakeBlockValue(getIndex(), 0, SetWiredFace(0, wiredFace));
		result.cellFace = raycastResult.cellFace;
		return result;
    }

} // namespace PocketSurvival

